package sjtu.ist.warehouse4ws.service;

import java.util.List;

import sjtu.ist.warehouse4ws.dao.PermissionDao;
import sjtu.ist.warehouse4ws.dao.cust.CustPermissionDao;
import sjtu.ist.warehouse4ws.model.CustPermission;
import sjtu.ist.warehouse4ws.model.Permission;
import sjtu.ist.warehouse4ws.tool.Constants;
import sjtu.ist.warehouse4ws.tool.PropertyHelper;

public class PermissionServiceImpl implements PermissionService{
	private PermissionDao permissionDao;
	private CustPermissionDao custPermissionDao;

	public void setPermissionDao(PermissionDao permissionDao) {
		this.permissionDao = permissionDao;
	}

	public void setCustPermissionDao(CustPermissionDao custPermissionDao) {
		this.custPermissionDao = custPermissionDao;
	}

	@Override
	public String addPermission(Permission permission,int companyId) {
		String result;
		if(companyId==Constants.ADMIN_COMPANY_ID){
			result=this.permissionDao.save(permission);
		}else{
			CustPermission cp=new CustPermission();
			PropertyHelper.copyProperties(permission, cp);
			result=custPermissionDao.save(cp);
		}
		return result;
	}


	@Override
	public List<Permission> getPermissionById(String id) {
		// TODO Auto-generated method stub
		return (List<Permission>)permissionDao.findPermissionById(id);
	}


	@Override
	public List<Permission> getPermissionByGroupId(String groupId) {
		// TODO Auto-generated method stub
		return permissionDao.findPermissionByGroupId(groupId);
	}

}
